package com.cyj.springioc2.main;

import com.cyj.springioc2.config.SpringConfig;
import com.cyj.springioc2.service.IUserService;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.sql.SQLException;

/**
 * @description:
 * @Author C_Y_J
 * @create 2021-02-26 15:03
 **/
public class UserDemo {
    public static void main(String[] args) throws SQLException {
//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
        IUserService userService = (IUserService) applicationContext.getBean("userService");
        userService.save();

        ComboPooledDataSource dataSource = (ComboPooledDataSource) applicationContext.getBean("dataSource");
        System.out.println(dataSource.getConnection());
        dataSource.close();
    }
}
